﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;
using CubicFWNet.Data.ViewModal;

namespace CubicFWNet.Data.SystemManager
{
    public class OriginalCostRepository : RepositoryBase<OriginalCost>
    {
        /// <summary>
        /// 查询原料成本表OriginalCosts
        /// </summary>
        /// <param name="status">状态</param>
        /// <param name="producName">产品名称</param>
        /// <param name="productNum">产品编号</param>
        /// <param name="technologyNum">工艺编号</param>
        /// <returns></returns>
        public IQueryable<ProductTechnologyView> GetList(int status, string producName, string productNum, string technologyNum)
        {
            var result = from ori in dbcontext.OriginalCosts
                         join tech in dbcontext.Technologies
                         on ori.TechnologytId equals tech.Id
                         join op in dbcontext.OrderProducts
                         on tech.OrderProductId equals op.Id
                         join pro in dbcontext.Products
                         on op.ProductId equals pro.Id
                         //join u in dbcontext.Users on tech.UserId equals u.Id
                         where (ori.Status == status)//status == -10 || 
                         && op.Status != -1
                         && (technologyNum == "" || tech.Number.Contains(technologyNum))
                         && (productNum == "" || pro.Number.Contains(productNum))
                         && (producName == "" || pro.Name.Contains(producName))
                         //into newpublisher
                         select new ProductTechnologyView
                         {
                             Number = tech.Number,
                             OrderProductId = tech.OrderProductId,
                             CreatorID = tech.CreatorID,
                             CreatorName = tech.CreatorName,
                             TechnologyNum = tech.Number,
                             ProductName = pro.Name,
                             ProductNumber = pro.Number,
                             Status = ori.Status,
                             CreateTime = ori.CreateTime,
                             ApplyTime = ori.ApplyTime,
                             Price = op.Price,
                             Id = ori.Id,
                             Materials = ori.Materials,
                             TechnologyId = ori.TechnologytId
                             //UserName = u.RealName
                         };
            return result;
        }



    }
}
